package com.nanning.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nanning.common.utils.StringUtils;
import com.nanning.system.domain.CarComplete;
import com.nanning.system.mapper.CarCompleteMapper;
import com.nanning.system.service.ICarCompleteService;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 各品类装车完成情况 服务实现类
 * </p>
 *
 * @author zhurenwang
 * @since 2025-05-03
 */
@Service
public class CarCompleteServiceImpl extends ServiceImpl<CarCompleteMapper, CarComplete> implements ICarCompleteService {

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void importData(Sheet sheet2) {
        baseMapper.delete(new QueryWrapper<>());
        int rows = sheet2.getPhysicalNumberOfRows();
        for (int i = 0; i < rows; i++) {
            if (i < 4) continue;
            CarComplete carComplete = new CarComplete();
            carComplete.setCategory(sheet2.getRow(i).getCell(1).getStringCellValue());
            if (StringUtils.isEmpty(carComplete.getCategory())) continue;
            carComplete.setMonthCarNum(String.valueOf(sheet2.getRow(i).getCell(5).getNumericCellValue()));
            carComplete.setYearCarNum(String.valueOf(sheet2.getRow(i).getCell(11).getNumericCellValue()));
            save(carComplete);
        }
    }
}
